import React from "react"
class TestComponent extends React.Component{
    state = {
        name:"张三"
    }
    // constructor(){
    //     super()
    //     this.changeName = this.changeName.bind(this)
    // }
    changeName=()=>{
        // this.state.name="李四"  不可以这样写会指向错误,写了constructor就可以用这个了
        this.setState({
            name:'李四'
        })
    }
    render(){
        return (
            <div>this is TestComponent
                当前name为：{this.state.name}
                <button onClick={this.changeName}>改name</button>
            </div>
        )
    }
}
function App () {
   return (
       <div>
           <TestComponent></TestComponent>
       </div>
   )
}
export default App